home *** CD-ROM | disk | FTP | other *** search
-
- #ifndef _EXCEPT_
- #define _EXCEPT_
-
- #ifndef _ODTYPES_
- #include "ODTypes.h"
- #endif
-
- #ifndef _ERRORDEF_
- #include "ErrorDef.xh" // Clients probably need the error codes as well
- #endif
-
- #ifndef __SETJMP__
- #include <setjmp.h>
- #endif
-
- #ifdef __LIBRARYMANAGER__
- #error "Please don't include both Except.h and LibraryManager.h"
- #endif
-
- #ifndef FWODEXCE_H
- #include "FWODExce.h"
- #endif
-
- #ifdef _OD_IMPL_
- #pragma import on
- #endif
-
- //=====================================================================================
- // ODVolatile
- //=====================================================================================
-
- // Any variable or parameter that is modified in a TRY block and used in the
- // CATCH block must be declared as volatile or it may have an incorrect value
- // in the CATCH block.
- // Since not all compilers support the 'volatile' keyword, use this instead;
-
- #ifndef _NATIVE_EXCEPTIONS_
- #define ODVolatile(x) ((void) &x)
- #else
- #define ODVolatile(x) /*no need for this with native exceptions*/
- #endif
-
- //=====================================================================================
- // Exception Handling Macros (native C++ exceptions)
- //=====================================================================================
-
- #ifdef _NATIVE_EXCEPTIONS_
-
- struct ODNativeException {
- ODError error;
- const char *message;
- };
-
- #define ErrorCode() (_exception.error)
- #define ErrorMessage() (&_exception.message)
-
- #define TRY \
- try {
-
- #define CATCH_ALL \
- } catch(ODNativeException _exception) {
-
- #define RERAISE \
- throw
-
- #define ENDTRY \
- }
-
- /* CATCH( ) will not work with native exceptions. Don't use it! */
-
-
- //=====================================================================================
- // Exception Handling Macros (emulated)
- //=====================================================================================
-
- #else /*not _NATIVE_EXCEPTIONS*/
-
- #define ErrorCode() (_except.GetODError())
- #define ErrorMessage() (NULL)
-
- #define TRY FW_TRY
-
- #define CATCH_ALL FW_CATCH_BEGIN FW_CATCH_REFERENCE(FW_XOpenDocException, _except)
-
- #define RERAISE FW_THROW_SAME()
-
- #define ENDTRY FW_CATCH_END
-
- // CATCH( ) is not compatible with native C++ exceptions.
- // Its use is discouraged.
- //#define CATCH(e) \
- // } else if (_except.fError==(e)) {
-
-
- #endif /*_NATIVE_EXCEPTIONS*/
-
- //=====================================================================================
- // Raising Exceptions
- //=====================================================================================
-
- inline void THROW(ODError error, const char* msg=NULL)
- {FW_THROW(FW_XOpenDocException(error)); }
- inline void THROW_IF_ERROR(ODError error, const char* msg=NULL)
- {if (error) FW_THROW(FW_XOpenDocException(error)); }
- inline void THROW_IF_NULL(void* value)
- {if (!value) FW_THROW(FW_XOpenDocException(kODErrOutOfMemory)); }
- inline void THROW_IF_NULL(void* value, const char* msg)
- {if (!value) FW_THROW(FW_XOpenDocException(kODErrOutOfMemory)); }
- inline void THROW_IF_NULL(void* value, ODError error)
- {if (!value) FW_THROW(FW_XOpenDocException(error)); }
-
- // Optional message parameters:
- #define THROW_M(error, m) THROW(error, m)
- #define THROW_IF_ERROR_M(error, m) THROW_IF_ERROR(error, m)
- #define THROW_IF_NULL_M(value, m) THROW_IF_NULL(value, m)
-
- // Call BreakOnThrow(TRUE) to break into the debugger whenever THROW is called.
- // (The call returns the previous value of the setting.)
- //ODBoolean BreakOnThrow( ODBoolean brk );
-
-
- //=====================================================================================
- // SOM Exception Utilities
- //=====================================================================================
-
- // This modified TRY block should be used in SOM methods. It's just like a
- // regular TRY...CATCH_ALL...ENDTRY except that the exception code will be
- // stored in the Environment. Needless to say you should _not_ reraise!
-
- #ifdef _NATIVE_EXCEPTIONS_
-
- #define SOM_TRY \
- TRY
-
- #define SOM_CATCH_ALL \
- CATCH_ALL \
- FW_SetODException(ev,ErrorCode());
-
- #define SOM_ENDTRY \
- ENDTRY
-
- #else /*not _NATIVE_EXCEPTIONS_*/
-
- #define SOM_TRY FW_TRY
-
- #define SOM_CATCH_ALL \
- FW_CATCH_BEGIN FW_CATCH_REFERENCE(FW_XOpenDocException, _except) \
- FW_SetODException(ev,ErrorCode());
-
- #define SOM_ENDTRY FW_CATCH_END
-
- #endif /*_NATIVE_EXCEPTIONS_*/
-
- #if 0
- // ODSetSOMException stores an OD error code in the environment.
- // ODGetSOMException returns the OD error code (if any) from an environment.
-
- void ODSetSOMException( Environment*, ODError, const char *msg =kODNULL );
-
- #ifdef _NATIVE_EXCEPTIONS_
- void ODSetSOMException( Environment*, ODNativeException& );
- #endif
-
- ODError ODGetSOMException( Environment *ev );
-
- // CHECK_ENV throws an exception if the environment indicates an error.
-
- void CHECK_ENV( Environment* );
-
- // SOMCHKEXCEPT is a macro that is called in a .xh file if the ev variable
- // indicates an exception is set.
- //#define SOMCHKEXCEPT {CHECK_ENV(ev);}
- #endif
-
-
- //=====================================================================================
- // Destructo, a C++ base class for auto-destruct objects
- //=====================================================================================
-
- class Destructo
- {
- #ifndef _NATIVE_EXCEPTIONS_
- protected:
- Destructo( ) {}; // [HLX] added to satisfy the
-
- public:
- virtual ~Destructo( );
-
- #if 0
- private:
- Destructo* EmergencyDestruct( );
- Destructo *fPrevDestructo;
- friend class ODExceptionFrame;
-
- #endif /*_NATIVE_EXCEPTIONS_*/
- static void* operator new( size_t ); // Make it illegal to allocate on heap
- // In future could use alloca??
- #endif // 0
- };
-
- #ifdef _OD_IMPL_
- #pragma import off
- #endif
-
-
- #endif // _EXCEPT_
-